package game.craft;

import game.craft.model.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: ccayirog
 * Date: Mar 27, 2011
 * Time: 12:08:03 AM
 * To change this template use File | Settings | File Templates.
 */
public class Board extends JPanel implements ActionListener {

    private Timer timer;
    private BoardItem boardItem = new BoardItem();
    private List<Item> aliens;


    public Board() {

        addKeyListener(new TAdapter());
        setFocusable(true);
        setBackground(Color.BLACK);
        setDoubleBuffered(true);
        setSize(400, 300);
        timer = new Timer(5, this);
        timer.start();
    }


    public void paint(Graphics g) {
        super.paint(g);
        boardItem.draw(g, this);
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }


    public void actionPerformed(ActionEvent e) {
        boardItem.move();
        checkCollisions();
        repaint();
    }

    public void checkCollisions() {
        boardItem.checkCollisions();
    }


    private class TAdapter extends KeyAdapter {

        public void keyReleased(KeyEvent e) {
            boardItem.keyReleased(e);
        }

        public void keyPressed(KeyEvent e) {
            boardItem.keyPressed(e);
        }
    }

}
